package com.ruix.app.model;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by hadexs on 2017/5/27.
 */

public class HXChatMessage {

//    ext

    private String groupId;
    private String from; //uid
    private String type; //类型 text img audio
    private String message;//消息
    private String fpath;//文件地址
    private int length;
    private int width;
    private int height;
//    private String ext;
    private JSONObject ext;





//    private ex


//    group_id	string	是			聊天室ID
//    from	string	是			作者
//    type	string	是			txt,img,audio
//    msg	string	是			消息内容,txt类型生效
//    fpath	string	是			文件阿里去路径img,audio时生效
//    length	integer	是			audio长，audio生效
//    width	integer	是			图长,img生效
//    height	integer	是			图宽，img生效
//    ext	string	是			扩展字段JSON


    public String getGroupId() {
        return groupId;
    }

    public void setGroupId(String groupId) {
        this.groupId = groupId;
    }

    public String getFrom() {
        return from;
    }

    public void setFrom(String from) {
        this.from = from;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getFpath() {
        return fpath;
    }

    public void setFpath(String fpath) {
        this.fpath = fpath;
    }

    public int getLength() {
        return length;
    }

    public void setLength(int length) {
        this.length = length;
    }

    public int getWidth() {
        return width;
    }

    public void setWidth(int width) {
        this.width = width;
    }

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    public void addExt(String key,JSONObject value) {
        if (ext == null){
            ext = new JSONObject();
        }
        try {
            ext.putOpt(key,value);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    public void addExt(String key,String value) {
        if (ext == null){
            ext = new JSONObject();
        }
        try {
            ext.putOpt(key,value);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    public void addExt(String key,boolean value) {
        if (ext == null){
            ext = new JSONObject();
        }
        try {
            ext.putOpt(key,value);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }


    public String getExt() {
        if (ext != null) {
            return ext.toString();
        }
        return "";
    }

    public boolean isText(){
        return "txt".equals(type);
    }

    public boolean isImage(){
        return "img".equals(type);
    }

    public boolean isVoice(){
        return "audio".equals(type);
    }

    public String identifier(){
        if (ext != null){
           return ext.optString("identifier");
        }
        return null;
    }
}
